package com.boomsecret.juc.atomic;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author wangjinliang on 2019/1/17.
 */
public class AtomicBooleanDemo {
    public static void main(String[] args) {
        AtomicBoolean a1 = new AtomicBoolean();
        // false
        System.out.println(a1.get());
        // true
        System.out.println(a1.compareAndSet(false, true));
        // true
        System.out.println(a1.getAndSet(false));

        System.out.println("-----------------");



        AtomicBoolean a2 = new AtomicBoolean(true);
        // true
        System.out.println(a2.get());
        // false
        System.out.println(a1.compareAndSet(false, true));
        a2.lazySet(false);
        // false
        System.out.println(a2.get());

        a2.set(true);
        // true
        System.out.println(a2.get());

        // true
        System.out.println(a2.weakCompareAndSet(true, false));
        // false
        System.out.println(a2.get());
        // false
        System.out.println(a2.weakCompareAndSet(true, true));
    }
}
